<?php
declare(strict_types=1);

namespace app\validate;

class UserAddressValidate extends BaseValidate
{
    protected $rule = [
        'id' => 'number',
        'address_type' => 'require|in:1,2',
        'province' => 'require|length:2,20',
        'city' => 'require|length:2,20',
        'county' => 'require|length:2,20',
        'address' => 'require|length:5,100',
        'username' => 'require|length:2,20',
        'phone' => 'require|mobile'
    ];

    protected $message = [
        'address_type.require' => '地址类型不能为空',
        'address_type.in' => '地址类型不正确',
        'province.require' => '省份不能为空',
        'province.length' => '省份长度必须在2-20个字符之间',
        'city.require' => '城市不能为空',
        'city.length' => '城市长度必须在2-20个字符之间',
        'county.require' => '区县不能为空',
        'county.length' => '区县长度必须在2-20个字符之间',
        'address.require' => '详细地址不能为空',
        'address.length' => '详细地址长度必须在5-100个字符之间',
        'username.require' => '联系人不能为空',
        'username.length' => '联系人长度必须在2-20个字符之间',
        'phone.require' => '手机号不能为空',
        'phone.mobile' => '手机号格式不正确'
    ];

    // 保存场景
    public function sceneSave(): UserAddressValidate
    {
        return $this->only(['id', 'address_type', 'province', 'city', 'county', 'address', 'username', 'phone']);
    }
} 